<template>
	<view class="report-list">
		<u-navbar title="财务历史" back-icon-color="#fff" title-color="#fff" :background="background"></u-navbar>
		<u-picker
			:mode="mode"
			:defaultTime="defaultTime"
			v-model="show"
			:params="params"
			:end-year="endYear"
			@confirm="confirm"
			cancel-text="还原"
			@cancel="cancel"
		></u-picker>
		<!-- 自定时间按钮 -->
		<view class="row-between custom-calendar" @click="showChange">
			<view class="row">
				<view class="calendar-icon">
					<u-icon name="calendar" color="#999" size="22px" ></u-icon>
				</view>
				
				<view class="ml10 lg">
					{{selectText == '' ? '自定义查询' : selectText}}
				</view>
			</view>
			<view class="">
				<u-icon name="arrow-right" color="#999" size="18px" ></u-icon>
			</view>
		</view>
		
		<!-- 列表 -->
		<block v-if="reportList.length > 0">
			<view class="data-list" v-for="(item, index) in reportList" :key="index">
				<view class="row-between data-list-item">
					<view class="">
						<view class="row">
							<view class="">
								{{item.date}}申报账单
							</view>
							<view class="pl20 pr20" @click="updateInfo" :data-id="item.id">
								<u-icon name="edit-pen" color="#2045fc" size="32"></u-icon>
							</view>
						</view>
						<view class="muted sm">
							{{item.createtime}}
						</view>
						
					</view>
					<view class="row-end" @click="clickDevelop" :data-index="index">
						<view class="mr10">
							￥{{item.total_money}}
						</view>
						<u-icon :name="item.is_develop ? 'arrow-up' : 'arrow-down'" color="#2045fc" size="16px" ></u-icon>
					</view>
				</view>
				
				<view class="list-child" v-show="item.is_develop">
					<view class="list-title">
						食材支出（秦隆）
					</view>
					<view class="">
						<!-- 蔬菜 -->
						<view class="row-between list-child-item">
							<view class="">
								蔬菜
							</view>
							<view class="">
								￥{{item.vegetables_price}}
							</view>
						</view>
						
						<!-- 食用油 -->
						<view class="row-between list-child-item">
							<view class="">
								食用油
							</view>
							<view class="">
								￥{{item.oil_price}}
							</view>
						</view>
						
						<!-- 调味品 -->
						<view class="row-between list-child-item">
							<view class="">
								调味品
							</view>
							<view class="">
								￥{{item.condiments_price}}
							</view>
						</view>
						
						<!-- 大米 -->
						<view class="row-between list-child-item">
							<view class="">
								大米
							</view>
							<view class="">
								￥{{item.rice_price}}
							</view>
						</view>
						
						<!-- 面粉 -->
						<view class="row-between list-child-item">
							<view class="">
								面粉
							</view>
							<view class="">
								￥{{item.flour_price}}
							</view>
						</view>
						
						<!-- 猪肉 -->
						<view class="row-between list-child-item">
							<view class="">
								猪肉
							</view>
							<view class="">
								￥{{item.meat_price}}
							</view>
						</view>
						
						<!-- 鸡肉 -->
						<view class="row-between list-child-item">
							<view class="">
								鸡肉
							</view>
							<view class="">
								￥{{item.chicken_price}}
							</view>
						</view>
						
						<!-- 牛羊肉 -->
						<view class="row-between list-child-item">
							<view class="">
								牛羊肉
							</view>
							<view class="">
								￥{{item.beef_mutton_price}}
							</view>
						</view>
						
						<!-- 鸡蛋 -->
						<view class="row-between list-child-item">
							<view class="">
								鸡蛋
							</view>
							<view class="">
								￥{{item.egg_price}}
							</view>
						</view>
						
						<!-- 干货 -->
						<view class="row-between list-child-item">
							<view class="">
								干货
							</view>
							<view class="">
								￥{{item.dry_price}}
							</view>
						</view>
						
						<!-- 水果 -->
						<view class="row-between list-child-item">
							<view class="">
								水果
							</view>
							<view class="">
								￥{{item.fruit_price}}
							</view>
						</view>
						
						<!-- 五谷 -->
						<view class="row-between list-child-item">
							<view class="">
								五谷
							</view>
							<view class="">
								￥{{item.grain_price}}
							</view>
						</view>
						
						<!-- 奶 -->
						<view class="row-between list-child-item">
							<view class="">
								奶
							</view>
							<view class="">
								￥{{item.milk_price}}
							</view>
						</view>
						
						<!-- 辅食 -->
						<view class="row-between list-child-item">
							<view class="">
								辅食
							</view>
							<view class="">
								￥{{item.side_dish_price}}
							</view>
						</view>
						
						<!-- 其他 -->
						<view class="row-between list-child-item">
							<view class="">
								其他
							</view>
							<view class="">
								￥{{item.other_price}}
							</view>
						</view>
						
						<!-- 伙食日劳务费 -->
						<view class="row-between list-child-item">
							<view class="">
								伙食日劳务费
							</view>
							<view class="">
								￥{{item.labor_price}}
							</view>
						</view>
					</view>
					
					<view class="list-title">
						食材支出（非秦隆）
					</view>
					<view>
						<!-- 未从秦龙下单物品 -->
						<view class="row-between list-child-item">
							<view class="">
								未从秦龙下单物品
							</view>
							<view class="">
								￥{{item.no_ql_order_price}}
							</view>
						</view>
						
						<!-- 外购馒头 -->
						<view class="row-between list-child-item">
							<view class="">
								外购馒头
							</view>
							<view class="">
								￥{{item.steamed_price}}
							</view>
						</view>
						
						<!-- 外购面条 -->
						<view class="row-between list-child-item">
							<view class="">
								外购面条
							</view>
							<view class="">
								￥{{item.noodles_price}}
							</view>
						</view>
					</view>
					
					<view class="list-title">
						杂费
					</view>
					<view class="">
						<view class="row-between list-child-item" v-if="item.labor_cost != 0">
							<view class="">
								杂费日劳务费
							</view>
							<view class="">
								￥{{item.labor_cost}}
							</view>
						</view>
						<view class="row-between list-child-item" v-for="(c_item, c_index) in item.otherlist">
							<view class="">
								{{c_item.spending}}
							</view>
							<view class="">
								￥{{c_item.actual_amount}}
							</view>
						</view>
					</view>
					
					<!-- <view class="list-title">
						间接成本（秦隆）
					</view>
					<view class="">
						<view class="row-between list-child-item">
							<view class="">
								后勤小件快消
							</view>
							<view class="">
								￥{{item.logistics_a_kuaixiao_price}}
							</view>
						</view>
						<view class="row-between list-child-item">
							<view class="">
								后勤小件厨具
							</view>
							<view class="">
								￥{{item.logistics_a_chuju_price}}
							</view>
						</view>
						<view class="row-between list-child-item">
							<view class="">
								办公用品
							</view>
							<view class="">
								￥{{item.office_supplies_price}}
							</view>
						</view>
						<view class="row-between list-child-item">
							<view class="">
								杂费日劳务费
							</view>
							<view class="">
								￥{{item.za_fee_labor_price}}
							</view>
						</view>
					</view>
					
					
					<view class="list-title">
						间接成本（非秦隆）
					</view>
					<view class="">
						<view class="row-between list-child-item">
							<view class="">
								学生奖品
							</view>
							<view class="">
								￥{{item.stu_prize_price}}
							</view>
						</view>
						
						<view class="row-between list-child-item">
							<view class="">
								维修补充
							</view>
							<view class="">
								￥{{item.maintenance_price}}
							</view>
						</view>
						
						<view class="row-between list-child-item">
							<view class="">
								员工房租
							</view>
							<view class="">
								￥{{item.ren_rent_price}}
							</view>
						</view>
						
						<view class="row-between list-child-item">
							<view class="">
								水电费
							</view>
							<view class="">
								￥{{item.electricity_water_price}}
							</view>
						</view>
						
						<view class="row-between list-child-item">
							<view class="">
								甲醇燃气费
							</view>
							<view class="">
								￥{{item.fuel_gas_price}}
							</view>
						</view>
						
						<view class="row-between list-child-item">
							<view class="">
								其他费用
							</view>
							<view class="">
								￥{{item.indrect_other_price}}
							</view>
						</view>
					</view> -->
					
					
				</view>
			</view>
			
			<u-loadmore :status="status" />
		</block>
		<block v-else>
			<u-empty text="当月暂无数据" mode="list" margin-top="80"></u-empty>
		</block>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#2165F7',
				},
				show: false,
				selectText: '',
				mode: 'time',
				endYear: '',
				defaultTime: '',
				params: {
					year: true,
					month: true,
				},
				reportList: [],
				postData: '',
				
				status: 'loadmore',
				page: 1,
				limit: 0,
				isLoading: false,
			}
		},
		onLoad() {
			var date = new Date(),
			year = date.getFullYear(),
			month = date.getMonth() + 1;
			
			this.defaultTime = year + '-' + month;
			this.endYear = year;
			
			this.reportListFun();
			
		},
		onReachBottom() {
			if(this.isLoading) return ;
			this.status = 'loading';
			this.page = ++ this.page;
			setTimeout(() => {
				this.reportListFun();
			}, 2000)
		},
		computed: {
			showBtnStatus() {
				return this.show ? 0 : 1;
			}
		},
		methods: {
			// 修改信息
			updateInfo(e) {
				let _id = e.currentTarget.dataset.id;
				
				uni.redirectTo({
					url: '/pages/finance/report?id='+_id
				})
			},
			showChange(index) {
				this.show = !this.show;
			},
			confirm(e) {
				this.selectText = '';
				if (this.params.year) this.selectText += e.year;
				if (this.params.month) this.selectText += '-' + e.month;
				
				this.onRefresh();
			},
			cancel(e) {
				this.selectText = '';
			},
			onRefresh() {
				this.status = 'loading';
				this.isLoading = false
				this.page = 1
				this.reportList = [];
				
				this.reportListFun();
			},
			
			//班级列表
			reportListFun() {
				let _date = this.selectText;
				let post_params = {
					limit: 15,
					page: this.page
				};
				
				if(_date != '') {
					post_params.date = _date
				}
				
				this.$u.post('/api/finance/foodPriceDetail', post_params).then(res => {
					let datalist = res.food;
					let _limit = res.limit;
					
					datalist.forEach(function(item,index) {
						item.is_develop = false;
					})
					if(datalist.length < _limit) {
						this.status = 'nomore';
						this.isLoading = true;
					}
					this.reportList = this.reportList.concat(datalist);
					// 计算总钱数
					this.reportList.forEach(function(item,index) {
						item.total_money = (parseFloat(item.price_week) + parseFloat(item.total_indirect_amount) + parseFloat(item.labor_cost)).toFixed(2)
					})
					this.limit = _limit;
				});
			},
			
			clickDevelop(e) {
				let _this = this;
				let _index = e.currentTarget.dataset.index;
				let _list = _this.reportList;
				
				_list[_index].is_develop = !_list[_index].is_develop;
				
				_this.reportList = _list;
				
			}
		}
	}
</script>

<style lang="scss">
	.report-list {
		
		.custom-calendar {
			padding: 30rpx;
			.calendar-icon {
				position: relative;
				
				&::after {
					content: "";
					position: absolute;
					width: 10rpx;
					height: 10rpx;
					border-radius: 50%;
					background-color: #de2626;
					top: 0;
					right: 0;
				}
			}
		}
		
		.data-list {
			border-bottom: 2rpx solid #f6f6f6;
			.data-list-item {
				padding: 20rpx 30rpx;
			}
			
			.list-child {
				.list-title {
					padding: 20rpx;
					background-color: #f6f6f6;
				}
				
				.list-child-item {
					padding: 30rpx;
					border-bottom: 2rpx solid #f6f6f6;
				}
				
			}
		}
	}
</style>
